# coding:utf-8
from django.conf.urls import include, url
from django.contrib.auth.decorators import login_required
from forum.views import IndexView, PostCreate, PostUpdate, PostDelete, \
    MessageCreate, MessageDetail, SearchView, UserPostView
from django.contrib import admin
from forum import views
from forum.manager_delete_decorator import delete_permission

admin.autodiscover()

urlpatterns = [
    url(r'^accounts/login/$', views.user_login, name='user_login'),
    url(r'^accounts/logout/$', views.user_logout, name='user_logout'),
    url(r'^accounts/register/$', views.user_register, name='user_register'),
    url(r'^$', IndexView.as_view(), name='index'),
    url(r'^columns/$', views.colum_nall, name='column_all'),
    url(r'^column/(?P<column_pk>\d+)/$',
        views.column_detail,
        name='column_detail'),
    url(r'^post_detail/(?P<post_pk>\d+)/$',
        views.post_detail,
        name='post_detail'),
    url(r'^make_friend/(?P<sender>\w+)/(?P<receiver>\w+)/$',
        views.make_friend,
        name='make_friend'),
    url(r'^make_comment/$', views.make_comment, name='make_comment'),
    url(r'^user/postlist/$', UserPostView.as_view(), name='user_post'),
    url(r'^user/post_create/$',
        login_required(PostCreate.as_view()),
        name='post_create'),
    url(r'^user/post_update/(?P<pk>\d+)/$',
        login_required(PostUpdate.as_view()),
        name='post_update'),
    url(r'^user/post_delete/(?P<pk>\d+)/$',
        delete_permission(login_required(PostDelete.as_view())),
        name='post_delete'),
    # url(r'^sendmessage/(?P<sender>\w+)/(?P<receiver>\w+)/$', views.sendmessage', name='send_message'),
    url(r'^user/notices/$', views.show_notice, name='show_notice'),
    url(r'^user/notices/(?P<pk>\d+)/$',
        views.notice_detail,
        name='notice_detail'),
    url(r'^user/friend/(?P<pk>\d+)/(?P<flag>\d+)/$',
        views.friend_agree,
        name='friend_agree'),  # pk为对方用户id
    url(r'^user/messagedetail/(?P<pk>\d+)/$',
        MessageDetail.as_view(),
        name='message_detail'),  # pk为消息id
    url(r'^user/message/sendto/(?P<pk>\d+)/$',
        MessageCreate.as_view(),
        name='send_message'),  # pk为对方用户id
    url(r'^search/$', SearchView.as_view(), name='search'),
    url(r'^validate/$', views.validate, name='validate'),
    url(r'^uploadimage/', views.upload_image, name='upload_image'),
]
